<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\TableAsset;
use app\models\AgentConfig;
use app\models\KeyMap;
use yii\helpers\Html;
use yii\helpers\Url;


/**
 * @var $this yii\web\View
 * @var $agent app\models\Agent
 */

ApiAsset::register($this);
LayerAsset::register($this);
TableAsset::register($this);

$this->title = '代理商详情';
$this->params['breadcrumbs'][] = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<table class="table table-striped table-bordered table-hover">
    <tr>
        <th colspan="2"><h4>基本信息</h4></th>
    </tr>
    <tr>
        <th>编号</th>
        <td><?php echo $agent->id;?></td>
    </tr>
    <tr>
        <th>卡数量</th>
        <td><?php echo $cardCount;?></td>
    </tr>
    <tr>
        <th>登录用户名</th>
        <td><?php echo Html::encode($agent->username);?></td>
    </tr>
    <tr>
        <th>登录密码</th>
        <td id="reset_password"><button class="btn btn-sm btn-warning" onclick="resetAgentPassword(<?php echo $agent->id;?>)">重置密码</button></td>
    </tr>
    <tr>
        <th>联系人</th>
        <td><?php echo Html::encode($agent->contact);?></td>
    </tr>
    <tr>
        <th>联系电话</th>
        <td><?php echo Html::encode($agent->tel);?></td>
    </tr>
    <tr>
        <th>公司名称</th>
        <td><?php echo Html::encode($agent->company);?></td>
    </tr>
    <tr>
        <th>税号</th>
        <td><?php echo Html::encode($agent->tax);?></td>
    </tr>
    <tr>
        <th>快递地址</th>
        <td><?php echo Html::encode($agent->express);?></td>
    </tr>
    <tr>
        <th>状态</th>
        <td><?php echo KeyMap::getValue('agent_status', $agent->status);?></td>
    </tr>
    <tr>
        <th>创建时间</th>
        <td><?php echo Yii::$app->formatter->asDatetime($agent->create_time);?></td>
    </tr>
    <tr>
        <th>是否可开下级代理</th>
        <td><?php $prepaidPostpaid = AgentConfig::getConfig($agent->id, 'multi_agent', '');
            echo ['' => '', '0' => '否', '1' => '是'][$prepaidPostpaid];?>
            
        </td>
    </tr>
    <tr>
        <button type="button" class="btn btn-default" onclick="window.history.go(-1);"><i class="ace-icon fa fa-arrow-left bigger-110"></i>返回</button> &nbsp;
        <button tyoe="button" class="btn btn-info" onclick="window.location.reload();"><i class="ace-icon fa fa-refresh bigger-110"></i>刷新</button> 
        
    </tr>
</table>
<script>
    /**
     * 重置代理商密码
     * @param id 代理商编号
     */
    function resetAgentPassword(id) {
        $.getJSON('<?php echo Url::to(['/admin/user/reset-agent-password']);?>', {id: id}, function (json) {
            if (callback(json)) {
                layer.msg('密码已重置。');
                $('#reset_password').html(json['new_password']);
            }
        });
    }
</script>
